package com.aaa.controller.scl;

import cn.hutool.json.JSONConfig;
import cn.hutool.json.JSONUtil;
import com.aaa.controller.BaseController;
import com.aaa.entity.system.PageEnty;
import com.aaa.entity.Result;
import com.aaa.entity.scl.Scl;
import com.aaa.service.scl.SclService;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 问题表(Scl)表控制层
 *
 * @author makejava
 * @since 2022-08-30 14:34:47
 */
@RestController
@RequestMapping("scl")
public class SclController extends BaseController {

    @Autowired
    SclService sclService;
    /**
     * @create by: Teacher马
     * @description:查询所有
     * @create time:

     * @return
     */
    @RequestMapping("/queryAll.do")
    public String queryAll(PageEnty pageEnty, Scl scl) {
        List<Scl> scls = sclService.queryAllUserPage(pageEnty, scl);
        Page page= (Page) scls;
        JSONConfig jsonConfig = JSONConfig.create().setDateFormat("yyyy-MM-dd HH:mm:ss");
        return JSONUtil.toJsonStr(success( page.getTotal(),page.getResult()), jsonConfig);

    }
    /**
     * @create by: Teacher马
     * @description:添加
     * @create time:

     * @return
     */
    @RequestMapping("/saveUser.do")
    public Result saveUser(Scl scl){
        boolean saveUser = sclService.saveUser(scl);
        if (saveUser){
            return success();
        }else {
            return fail();
        }

    }
    /**
     * @create by: Teacher马
     * @description:删除
     * @create time:

     * @return
     */
    @RequestMapping("/deleteUser.do")
    public Result deleteUser(int[] id){
        boolean deleteUser = sclService.deleteUser(id);
        if (deleteUser){
            return success();
        }else {
            return fail();
        }
    }
    /**
     * @create by: Teacher马
     * @description:修改
     * @create time:

     * @return
     */
    @RequestMapping("/updateUser.do")
    public Result updateUser(Scl scl)  {
        boolean updateUser = sclService.updateUser(scl);
        if (updateUser){
            return success();
        }else {
            return fail();
        }
    }

    /**
     * @create by: feng (zhaixing@163.com)
     * @description: 题目唯一性校验
     * @create time: 2022/7/14 17:00
     * @param "QuestionFpa"
     * @return MyReturn
     */
    @GetMapping("repetitionName.do")
    public Result repetitionName(Scl scl){
        boolean b = this.sclService.repetitionName(scl);
        if (b){
            return success("问题可用");
        }
        return fail("问题重复，不可用");
    }

/**
 * @create by: Teacher马
 * @description: 如果使用了restController注解，页面跳转不能使用上面的String
 * @create time:

 * @return
*/
    @RequestMapping("/sclUser.do")
    public ModelAndView sclUser(ModelAndView modelAndView ){
        modelAndView.setViewName("scl/showScl");
        return  modelAndView;
    }

}

